<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id = "btn1">测试按钮1</button>
    <button id = "btn2">测试按钮2</button>

    <script>
        /*老版写法*/
        var btn1 = document.getElementById("btn1");
        btn1.onclick = function(){
            alert('按钮1已被点击');
        }


        /*新版写法*/
        var btn2 = document.getElementById("btn2");

        btn2.addEventListener("click", function(){
            alert('按钮2已被点击');
        })
    </script>
</body>
</html>